<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){
    		$name = I('get.name');
		
		$map = array();
			if(isset($name)){
				$map['fi.film_name_real'] = array('like','%'.$name.'%');
			}
			$count= M('FilmInfo')->alias('fi')->where($map)->count();
			//echo M('FilmInfo')->getLastSql();
			$page = new \Think\Page($count,20);
			$res = M('FilmInfo')->alias('fi')->field("fi.*,fd.film_type as type")->join('left join ot_film_detail as fd on fd.film_id = fi.id')->where($map)->limit($page->firstRow.','.$page->listRows)->select();
			//echo M('FilmInfo')->getLastSql();
			//dump($res);
			$film_type = C("FILM_TYPE");
			foreach($res as $key => $val)
			{
				$res[$key]['film_type'] = $film_type[$val['film_type']];
				$res[$key]['film_publish_time'] = date('Y-m-d h:i:s',$val['film_publish_time']);
				$res[$key]['film_name_real'] = explode('/',$val['film_name_real'])[0];
				$res[$key]['click_num'] = D('FilmClick')->get_click_num($val['id']);
			}
		//echo M('FilmInfo')->getLastSql();
		//dump($res);
		$this->assign('page',$page->show());
		$this->assign('count',$count);
		$this->assign('data',$res);        
        $this->display();
    }


}